package com.venusic.handwritedemo;

import com.venusic.handwritedemo.slice.MainAbilitySlice;
import ohos.aafwk.ability.Ability;
import ohos.aafwk.content.Intent;
import ohos.agp.window.dialog.ToastDialog;
import ohos.bundle.IBundleManager;


public class MainAbility extends Ability {
    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setMainRoute(MainAbilitySlice.class.getName());

        /*
            此处暂未用到开发版本和系统版本的判断 Build.VERSION_CODES.M暂无对应的鸿蒙方法
         */
//        if (SystemVersion.getApiVersion() >= Build.VERSION_CODES.M) {
        if (this.verifySelfPermission("ohos.permission.WRITE_MEDIA") != IBundleManager.PERMISSION_GRANTED) {
            requestPermissionsFromUser(new String[]{"ohos.permission.WRITE_MEDIA"}, 0x555);
        }
//        }

    }

    @Override
    public void onRequestPermissionsFromUserResult(int requestCode, String[] permissions, int[] grantResults) {
        super.onRequestPermissionsFromUserResult(requestCode, permissions, grantResults);
        if (grantResults[0] != IBundleManager.PERMISSION_GRANTED) {
            ToastDialog toastDialog = new ToastDialog(this);
            toastDialog.setText( "您拒绝了读写存储权限！").setDuration(5000).show();
        }
    }

}
